package com.ace3l.legal.backend.dao;

import javax.persistence.*;
import java.util.List;
import java.util.Map;
import java.util.Iterator;

/**
 * Created by IntelliJ IDEA.
 * User: ageer
 * Date: Jul 27, 2008
 * Time: 5:32:45 PM
 * To change this template use File | Settings | File Templates.
 */
public class GeneralDao  extends ADao{
    public List runSQL(String table, String fields) {
        Query q = entityManager.createQuery("select " + fields + " from " + table);
        return q.getResultList();
    }

    public List runNamedQuery(String query, Map<String,Object> params) {
        Query q = entityManager.createNamedQuery(query);
        Iterator<String> itKeys = params.keySet().iterator();

        while (itKeys.hasNext()) {
            String paramName = itKeys.next();
            Object paramValue = params.get(paramName);
            try {
                q.setParameter(paramName,paramValue);
            } catch (Exception e) { }
        }
        return q.getResultList();
    }

}
